package com.hqq.exercise.string;

/**
 * WrongInput 还原错误输入的字符串
 * 题目描述:
 * 手放在键盘上 稍微不注意往左就会出错 输入一个错位后敲出的字符串 输出打字员本来想打出的句子
 * 样例输入: O S, GOMR YPFSU/
 * 样例输出: I AM FINE TODAY.
 * Created by heqianqian on 2017/8/8.
 */
public class WrongInput {

    private static final char[] keyWord = {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\\',
            'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'',
            'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/'};

    public static String restoreInput(String input) {
        char[] charArray = input.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            for (int j = 1; j < keyWord.length; j++) {
                if (keyWord[j] == charArray[i]) {
                    charArray[i] = keyWord[(j-1)<0?(keyWord.length-1):(j-1)];
                    break;
                }
            }
        }
        return new String(charArray);
    }

}
